#include <assert.h>
#include "widgets.h"
#include "form_win31.h"

namespace viswidgets
{

static view_t* create_form_by_style(view_t* parent, widget_style style)
{
	if (widget_style_win31 == style)
	{
		form_win31_impl* impl = new form_win31_impl(parent);
		assert(NULL != impl);
		return impl->getview();
	}
	// todo: else
	return NULL;
}

form::form(const visgrph::canvas& c, widget_style style)
: m_style(style)
{
	m_view = create_form_by_style(NULL, style);
	canvas(c);
}

form::form(const form& parent)
: m_style(parent.m_style)
{
	m_view = create_form_by_style(parent, m_style);
}

form::form(view_t* parent, widget_style style)
	: m_style(style)
{
	m_view = create_form_by_style(parent, style);
}

form::form(int left, int top, int width, int height,
	view_t* parent, widget_style style)
	: m_style(style)
{
	if (widget_style_win31 == style)
	{
		form_win31_impl* impl = new form_win31_impl(
			left, top, width, height, parent);
		assert(NULL != impl);
		m_view = impl->getview();
	}
	// todo: else
}

form::operator view_t*(void) const
{
	if (widget_style_win31 == m_style)
	{
		form_win31_impl* impl = widget_downcast(form_win31_impl, m_view->data);
		return impl->client_view();
	}
	// todo:
	return NULL;
}

form::~form()
{
}

void form::canvas(const visgrph::canvas& c)
{
	if (widget_style_win31 == m_style)
	{
		form_win31_impl* impl = widget_downcast(form_win31_impl, m_view->data);
		if (NULL == impl) return;
		impl->canvas(c);
	}
	// else todo
}

void form::caption(const char* cap)
{
	if (widget_style_win31 == m_style)
	{
		form_win31_impl* impl = widget_downcast(form_win31_impl, m_view->data);
		if (NULL == impl) return;
		impl->caption(cap);
	}
	// else todo
}

}; // viswidgets
/* EOF */
